﻿

using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
using CTP.CRM.Core;
using Volo.Abp.Emailing;
using Microsoft.Extensions.DependencyInjection;
using CTP.CRM.Core.SqlSugar;
using CTP.CRM.Core.SqlSugar.Options;
using SqlSugar;
using CTP.CRM.Core.MongoDB;

namespace CTP.CRM.Repository
{
    /// <summary>
    /// 仓储模块
    /// </summary>
    [DependsOn(typeof(AbpAutofacModule), typeof(AbpEmailingModule))]
    public class RepositoryModule : AbpModule
    {
        /// <summary>
        /// 预配置服务
        /// </summary>
        /// <param name="context"></param>
        public override void PreConfigureServices(ServiceConfigurationContext context)
        {
            var configuration = context.Services.GetConfiguration();

            context.Services.AddSqlsugar(options =>
            {
                options.AddRange(new List<SqlsugarOptions> {
                    new SqlsugarOptions()
                    {
                        ConnectionString = configuration["ConnectionStrings:DefaultConnection"],
                        DbType = DbType.MySql,
                        IsAutoCloseConnection = true,
                        ConfigId = "default"
                    },
                    new SqlsugarOptions()
                    {
                        ConnectionString = configuration["ConnectionStrings:CTPBiCenterConnection"],
                        DbType = DbType.MySql,
                        IsAutoCloseConnection = true,
                        ConfigId = "CTPbicenter"
                    }
                });
            }, DataBaseContext.OnExcutingAction, "CTP.CRM.Repository");


            context.Services.AddMongoDB(options =>
            {
                options.ConnectionString = configuration["MongoDB:ConnectionString"];
                options.DataBaseName = configuration["MongoDB:DataBaseName"];
            });

        }
    }
}
